﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CardInChina.Common.Tool;

namespace CardInChina.Bussiness.Frontend.Models
{
    public class PayTencentCFT : PayInterfaceModel
    {
        [Field("cmdno")]
        public string CMDNo { get; set; }

        [Field("date")]
        public string Date { get; set; }

        [Field("bank_type")]
        public string BankType { get; set; }

        [Field("desc")]
        public string Description { get; set; }

        [Field("purchaser_id")]
        public string PurchaserId { get; set; }

        [Field("bargainor_id")]
        public string BargainorId { get; set; }

        [Field("transaction_id")]
        public string TransactionId { get; set; }

        [Field("sp_billno")]
        public string SPBillNo { get; set; }

        [Field("total_fee")]
        public string TotalFee { get; set; }

        [Field("fee_type")]
        public string FeeType { get; set; }

        [Field("return_url")]
        public string ReturnUrl { get; set; }

        [Field("attach")]
        public string Attach { get; set; }

        [Field("sign")]
        public string Sign { get; set; }

        public string QQPayKey { get; set; }

        public PayTencentCFT()
            : base("https://www.tenpay.com/cgi-bin/v1.0/pay_gate.cgi", "post")
        {
        }


        public override string Render()
        {
            this.Sign =
                "cmdno=" + CMDNo + "&date=" + Date + "&bargainor_id=" + BargainorId + "&transaction_id=" + TransactionId + "&sp_billno=" + SPBillNo + "&total_fee=" + TotalFee + "&fee_type=" + FeeType + "&return_url=" + ReturnUrl + "&attach=" + Attach + "&key=" + QQPayKey;
            this.Sign = MD5.GetHash(this.Sign);
            return base.Render();
        }

        protected override void RenderSubmit(StringBuilder sb)
        {
            sb.Append("<input name=\"Submit\" type=\"submit\" value=\"财付通\"/>");
        }
    }
}
